
package acctest.fixture;
import java.awt.List;
import java.sql.SQLException;
import java.sql.Timestamp;

import run.ServerFrame;
import server.SimpleServer;
import client.Message;
import db.parking.beans.Customer;
import db.parking.beans.Orders;
import db.parking.beans.Sms;
import db.parking.beans.Subscriber;
import db.tables.AdminCustomer;
import db.tables.AdminOrders;
import db.tables.AdminSMS;
import fit.ActionFixture;


public class cancelOrder extends ActionFixture {
	
	private ServerFrame server;
	private List liste = new List();
	private Orders o1;
	private SimpleServer simple;
	private Message msg = null;
	private Timestamp startTimestamp = null;
	private Timestamp leaveTimestamp = null;
	private Timestamp currTimestamp = null;

	
	
	public cancelOrder() throws SQLException
	{
		server= new ServerFrame(12345);
		server.setDbUser("root");
		server.setDbPass("31387650");
		server.setDbHost("localhost");
		server.setDbName("vcp");
		server.setDbPort("3306");
		
		
		server.listen();
		msg = new Message();
		o1 = new Orders();
	}
	

	public void addHours(int hours)
	{
		long time = System.currentTimeMillis();// Set current time at this second to StartTime
		currTimestamp = new Timestamp(time);
		startTimestamp = new Timestamp(time);
		leaveTimestamp = new Timestamp(time);
		startTimestamp.setHours(currTimestamp.getHours()+hours);
		leaveTimestamp.setHours(startTimestamp.getHours()+2);
	}
	
	public void tempCustomerId(String cusID) throws Exception
	{
		o1.setUid(cusID);
		AdminCustomer.update(cusID, 0);
	}
	public void carNo(String carNo)
	{
		o1.setCarNo(carNo);
	}
	public void createTemporaryOrder() throws Exception
	{
	
		o1 = new Orders(o1.getUid(), "Temporary", o1.getCarNo(),
				startTimestamp, leaveTimestamp, 3, "e@e.com",0);
		msg.setObj(o1);
		server.getServer().AddTemporaryOrder(msg);
		o1 = AdminOrders.getRow(o1.getUid(),o1.getCarNo());//add oid
		
	}
	
	public float cancel() throws SQLException
	{
		msg.setObj(o1);
		server.getServer().CancelOrder(msg);
		Customer c = AdminCustomer.getCustomerBalance(o1.getUid());
		return (float) c.getAmount();
	}
	
	public boolean checkOrderCancel() throws SQLException
	{
		 if (AdminOrders.getRow(o1.getUid(),o1.getCarNo()).getStatus() == 3)
			 return true;
		 else 
			 return false;
	}
		
		


  }

